package com.yantong.controller.api;

import com.yantong.pojo.Activity;
import com.yantong.pojo.ActivityParam;
import com.yantong.service.ActivityService;
import com.yantong.controller.BaseController;
import com.yantong.result.ResultVo;
import com.yantong.pojo.ProductAuthority;
import com.yantong.service.ProductAuthorityService;
import com.yantong.controller.BaseController;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 营销活动管理
 *
 * @author kanghaixin
 * @date 2018/9/7.15:39
 */
@ApiIgnore
@Controller
@RequestMapping("/wxapi/activity")
public class ApiActivityController extends BaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(ApiActivityController.class);

    @Autowired
    private ActivityService activityService;
    @Autowired
    private ProductAuthorityService productAuthorityService;

    /**
     * 获取营销活动列表
     *
     * @param offset
     * @param limit
     * @param activityParam
     * @return
     */
    @ApiOperation(value = "获取营销活动列表")
    @GetMapping("/getActivityList")
    @ResponseBody
    public ResultVo listAll(int offset, int limit, ActivityParam activityParam) {
        ResultVo resultVo = ResultVo.ok();
        return resultVo.put("data",activityService.listAll(offset, limit, activityParam));
    }

    /**
     * 根据赠送权限和门店id获取大礼包列表
     *
     * @param offset
     * @param limit
     * @param
     * @return
     */
    @ApiOperation(value = "根据赠送权限和门店id获取大礼包列表")
    @GetMapping("/selectActivityList")
    @ResponseBody
    public ResultVo selectActivityList(Long handselProductAuthorityId,int offset, int limit) {
        ResultVo resultVo = ResultVo.ok();
        return resultVo.put("data",activityService.selectActivityList(handselProductAuthorityId,offset, limit));
    }

    @ApiOperation(value = "根据大礼包id获取赠送商品的权限")
    @GetMapping("/selectActivityListByHandselProductAuthorityId")
    @ResponseBody
    public ResultVo selectActivityListByHandselProductAuthorityId(Long activityId,int offset, int limit) {
        if(activityId == null){
            return  ResultVo.error(412,"大礼包编号不能为空");
        }
        Activity activity = activityService.getActivityById(activityId);
        ProductAuthority productAuthority = productAuthorityService.getProductAuthorityById(activity.getHandselProductAuthorityId());
        ResultVo resultVo = ResultVo.ok();
        return resultVo.put("data",productAuthority);
    }

    /**
     * 根据购买权限获取大礼包列表
     *
     * @param offset
     * @param limit
     * @param
     * @return
     */
    @ApiOperation(value = "根据购买权限获取大礼包列表")
    @GetMapping("/selectActivityListByShopProductAuthorityId")
    @ResponseBody
    public ResultVo selectActivityListByShopProductAuthorityId(Long shopProductAuthorityId,int offset, int limit) {
        ResultVo resultVo = ResultVo.ok();
        return resultVo.put("data",activityService.selectActivityListByShopProductAuthorityId(shopProductAuthorityId,offset, limit));
    }

    /**
     * 获取营销活动详情
     *
     * @param productId
     * @return
     */
    @ApiOperation(value = "获取营销活动详情")
    @GetMapping("/detail")
    @ResponseBody
    public ResultVo getActivityDetail(Long memberId, Long productId) throws IllegalAccessException {
        ResultVo resultVo = ResultVo.ok();
        resultVo.put("success", true);
        resultVo.put("data", activityService.getActivityDetail(memberId,productId));
        resultVo.put("time", System.currentTimeMillis());
        return resultVo;
    }
}
